package com.yz.jdd.module.settings.precenter;

import com.yz.jdd.base.entity.Response_Base;
import com.yz.jdd.module.settings.model.VoiceConfig;
import com.yz.jdd.module.settings.view.VoiceSettingView;
import com.yz.jdd.network.MySubscriber;
import com.yz.jdd.network.NetWorkRequset;
import com.yz.jdd.network.request.Request_CancelOrderSetting;
import com.yz.jdd.network.request.Request_Status;
import com.yz.jdd.network.request.Request_VoiceSetting;
import com.yz.jdd.network.request.Request_shopList;
import com.yz.jdd.network.request.Request_userSwitchSetting;
import com.yz.jdd.network.response.Response_AppVoiceSet;
import com.yz.jdd.network.response.Response_UserSwitchSetting;
import com.yz.jdd.network.response.Response_VoiceStatus;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 克林
 * 语音设置界面控制器
 */
public class VoiceSettingPresenter {

    public VoiceSettingPresenter(VoiceSettingView voiceSettingView) {
        this.voiceSettingView = voiceSettingView;
    }

    VoiceSettingView voiceSettingView;
    /**
     * 获取开关状态
     */
    public void  getVoiceStatus(){
        voiceSettingView.showLoading();
        NetWorkRequset.queryAppVoiceSet(new MySubscriber() {
            @Override
            public void onSuccess(Response_Base response_baseModel) {
                Response_AppVoiceSet response_appVoiceSet= (Response_AppVoiceSet) response_baseModel.getResultObject();
                voiceSettingView.hidenLoading();
                voiceSettingView.showView(response_appVoiceSet);
            }

            @Override
            public void onNeedLogin(String msg) {
                voiceSettingView.hidenLoading();
            }

            @Override
            public void onFail(Response_Base response_baseModel) {
                voiceSettingView.hidenLoading();
            }
        });
    }

    /**
     * 开启或者关闭门店语音播报
     * 此方法已不在使用
     */
    public void setVoiceSetting(int voiceStatus,String shopId,String shopName) {
        Map<String ,Object> request_voiceSetting=new HashMap<>();
        request_voiceSetting.put("shopId",shopId);
        request_voiceSetting.put("status",voiceStatus);
        request_voiceSetting.put("shopName",shopName);

        voiceSettingView.showLoading();
        NetWorkRequset.setVoiceSetting(request_voiceSetting, new MySubscriber() {
            @Override
            public void onSuccess(Response_Base response_baseModel) {
                Response_AppVoiceSet response_voiceStatus= (Response_AppVoiceSet) response_baseModel.getResultObject();
                voiceSettingView.hidenLoading();
                voiceSettingView.showView(response_voiceStatus);

            }

            @Override
            public void onNeedLogin(String msg) {
                voiceSettingView.hidenLoading();
            }

            @Override
            public void onFail(Response_Base response_baseModel) {
                voiceSettingView.hidenLoading();


            }
        });
    }

    /**
     * 取消播报
     * @param status
     */
    public void setCancelOrderSetting(final String status){
//        Request_CancelOrderSetting request_cancelOrderSetting=new Request_CancelOrderSetting();
        voiceSettingView.showLoading();
        Request_Status request_status=new Request_Status();
        request_status.setStatus(status);
        NetWorkRequset.setCancelOrderSetting(request_status, new MySubscriber() {
            @Override
            public void onSuccess(Response_Base response_baseModel) {
                voiceSettingView.hidenLoading();
                voiceSettingView.showCancelOrderView(status);
            }

            @Override
            public void onNeedLogin(String msg) {
                voiceSettingView.hidenLoading();
            }

            @Override
            public void onFail(Response_Base response_baseModel) {
                voiceSettingView.hidenLoading();
            }
        });
    }

    /**
     * 语音播报开关设置
     * @param request_userSwitchSetting
     */
    public void doUserSwitchSetting(final Request_userSwitchSetting request_userSwitchSetting) {
        voiceSettingView.showLoading();
        NetWorkRequset.doUserSwitchSetting(request_userSwitchSetting, new MySubscriber() {
            @Override
            public void onSuccess(Response_Base response_baseModel) {
                voiceSettingView.hidenLoading();
                Response_UserSwitchSetting response_userSwitchSetting=
                        (Response_UserSwitchSetting) response_baseModel.getResultObject();
                if(response_userSwitchSetting!=null){
                    voiceSettingView.showUserSwitchSetting(request_userSwitchSetting.getSwitchType(),
                            response_userSwitchSetting);

                }

            }

            @Override
            public void onNeedLogin(String msg) {
                voiceSettingView.hidenLoading();
            }

            @Override
            public void onFail(Response_Base response_baseModel) {
                voiceSettingView.hidenLoading();
            }
        });
    }

    /**
     * 设置门店接口
     * @param request_shopList
     */
    public void doAppVoiceShopListSet(Request_shopList request_shopList) {

        NetWorkRequset.doAppVoiceShopListSet(request_shopList, new MySubscriber() {
            @Override
            public void onSuccess(Response_Base response_baseModel) {
                Response_AppVoiceSet response_appVoiceSet= (Response_AppVoiceSet) response_baseModel.getResultObject();
                voiceSettingView.showView(response_appVoiceSet);
            }

            @Override
            public void onNeedLogin(String msg) {

            }

            @Override
            public void onFail(Response_Base response_baseModel) {

            }
        });
    }
}
